package com.cmbdb.core.common;


import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import tk.mybatis.mapper.common.Mapper;

import java.util.List;


/**
 * 注释
 *
 * @author: coding99
 * @Date: 17-3-3
 * @Time: 上午11:28
 */
public abstract class BaseServiceImpl<T> implements BaseService<T> {

    @Autowired
    protected Mapper<T> mapper;

    public Mapper<T> getMapper() {
        return mapper;
    }

    /**
     * 判断数据库操作是否成功
     *
     * @param result
     * @return
     */
    protected boolean retBool(int result) {
        return (result  >= 1) ? true : false;
    }

    @Override
    public boolean insert(T entity) {
        return retBool(mapper.insert(entity));
    }

    @Override
    public boolean insertSelective(T entity) {
        return retBool(mapper.insertSelective(entity));
    }

    @Override
    public boolean deleteByPrimaryKey(Object id) {
        return retBool(mapper.deleteByPrimaryKey(id));
    }

    @Override
    public boolean delete(T entity) {
         return retBool(mapper.delete(entity));
    }

    @Override
    public boolean updateByPrimaryKeySelective(T entity) {
        return retBool(mapper.updateByPrimaryKeySelective(entity));
    }

    @Override
    public boolean updateByPrimaryKey(T entity) {
        return retBool(mapper.updateByPrimaryKey(entity));
    }

    @Override
    public T selectByPrimaryKey(Object id) {
        return mapper.selectByPrimaryKey(id);
    }

    @Override
    public List<T> selectAll() {
        return mapper.selectAll();
    }

    @Override
    public T selectOne(T entity) {
        return mapper.selectOne(entity);
    }

    @Override
    public List<T> select(T record) {
        return mapper.select(record);
    }

    @Override
    public List<T> selectByPage(T entity, int page, int rows) {

        PageHelper.startPage(page,rows);
        return mapper.selectAll();
    }

}
